#!/bin/sh
echo =================================
echo  Automated deployment scripts start...
echo =================================

echo Stop the project in progress...
APP_NAME=chanlin

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Stop Process...'
    kill -15 $tpid
fi
sleep 2
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi

echo Ready to pull the latest code from the Git repository..
cd /root/chanlin

echo Start pulling the latest code from the Git repository..
git pull origin master
echo Code pull complete..

echo Start packing...
mvn clean package -Dmaven.test.skip=true
#output=`mvn clean package`


cd /root/chanlin/target

echo initiate a project...
nohup java -jar chanlin-1.0.0.jar &> /root/chanlin/chanlin.log&
#java -jar chanlin-1.0.0.jar
echo success a project!
